package edu.hawaii.myisern.action;

import net.sourceforge.stripes.action.ActionBeanContext;
import java.util.ArrayList;
import java.util.List;

/**
 * Context class that extends the base ActionBeanContext class.  Used
 * to keep data that is relevent to each context.
 * @author Ben
 *
 */
public class MyIsernContext extends ActionBeanContext {

  private List<String> listRow;
  private char display;
  private String banner;

  /**
   * Sets the "login" attribute to true.
   * @param b is true if logged in.
   */
  public void setLoggedIn(boolean b) {
    if (b) {
      this.getRequest().getSession().setAttribute("login", "true");
    }
    else {
      this.getRequest().getSession().setAttribute("login", "false");
    }
  }

  /**
   * Sets the current record to edit.
   * 
   * @param name Name of current record.
   * 
   */
  public void setCurrentRecord(String name) {
    this.getRequest().getSession().setAttribute("recordname", name);
  }
  
  
  /**
   * Sets the current record to edit.
   * 
   * @return Name of current record.
   */
  public String getCurrentRecord() {
    return (String) this.getRequest().getSession().getAttribute("recordname");
  }
  /**
   * returns true if the login attribute of the context is true.
   * @return true if the user is logged in.
   */
  public boolean getLoggedIn() {
    try {
      return this.getRequest().getSession().getAttribute("login").equals("true");
    }
    catch (Exception e) {
      return false;
    }
  }
  
  /**
   * Sets the current row being held in the list.
   * @param fillRow The row to be saved in the context.
   */
  public void setListRow(List<String> fillRow) {
    listRow = new ArrayList<String>();
    for (String item : fillRow) {
      listRow.add(item);
    }
    this.getRequest().getSession().setAttribute("currentRow", listRow);
  }
  
  /**
   * Gets the list of the current row being held.
   * @return List containing a row of elements.
   */
  @SuppressWarnings("unchecked")
  public List<String> getListRow() {
    listRow = (List<String>) this.getRequest().getSession().getAttribute("currentRow");
    
    return this.listRow;
    
  }
  
  /**
   * Sets the display setting (either O, C, or R)
   * @param current the char corresponding to the display setting.
   */
  public void setDisplay(char current) {
    this.display = current;
  }
  
  /**
   * Gets the display setting (either O, C, or R)
   * @return char containing the current display setting.
   */
  public char getDisplay() {
    return this.display;
  }
  
  /**
   * Gets the banner message.
   * @return The manner message to be displayed.
   */
  public String getBanner() {
    return this.banner;
  }

  /**
   * Sets the banner message to be displayed.
   * @param value the string for the banner.
   */
  public void setBanner(String value) {
    this.banner = value;
  }
  
}
